package com.swingson.properties.impl;

import com.swingson.SwingsonGui;
import com.swingson.jsonparser.JsonElement;
import com.swingson.properties.impl.PropertyProcessors.PrimitivePropertyProcessor;
import javax.swing.ButtonGroup;
import javax.swing.JComponent;
import javax.swing.JRadioButton;

/**
 * @author sad
 */
public class RadioGroupPropertyProcessor extends PrimitivePropertyProcessor {

    @Override
    protected Object getValue(JsonElement jsonElement, JComponent component, SwingsonGui gui, String propertyName) {
        String value = jsonElement.getAsString();
        ButtonGroup group = gui.getRadioButtonGroupsMap().get(value);
        if (group == null) {
            group = new ButtonGroup();
            gui.getRadioButtonGroupsMap().put(value, group);
        }
        group.add((JRadioButton) component);
        return null;
    }
}
